home *** CD-ROM | disk | FTP | other *** search
- {$F+}
- {$G+}
-
- Unit XMS;
-
- {
- Extended memory (via XMS) handling routines
- by Maple Leaf, 1996
- }
-
- Interface
-
- Type
- EMM_Struct = record
- Count : LongInt;
- SourceHandle : Word;
- OffsetIntoSource : LongInt;
- DestHandle : Word;
- OffsetIntoDest : LongInt;
- end;
-
- Var
- XMS_Driver_Address : Pointer;
- XMS_Installed : Boolean;
- XMS_Error : byte;
- XMS_Move : EMM_Struct;
- XMS_Total,
- XMS_Largest : word;
-
- Procedure CheckXMSInstall; far;
- Function XMSVersion : word; far;
- Procedure AllocXMS ( Var Handle:word; Size:word ); far;
- Procedure FreeXMS ( Handle:Word ); far;
- Procedure LockXMS ( Handle:word; Size:word ); far;
- Procedure UnLockXMS ( Handle:word; Size:word ); far;
- Procedure MoveXMS ( Var EmmStruc:EMM_Struct ); far;
- Procedure LocalEnableA20; far;
- Procedure LocalDisableA20; far;
- Procedure CopyToXMS ( Var Source; Handle:Word; Offs:LongInt; Count:LongInt ); far;
- Procedure CopyFromXMS ( Handle:Word; Offs:LongInt; Var Dest; Count:LongInt ); far;
- Procedure CopyXMStoXMS ( SHandle:Word; SOffs:LongInt; DHandle:Word; DOffs:LongInt; Count:LongInt ); far;
- Procedure QueryXMS; far;
- Function CountXMS : Word; far;
-
- Implementation
-
- Procedure CheckXMSInstall;assembler;
- asm
- push es
- mov ax,4300h
- int 2fh
- cmp al,80h
- je @Inst
- mov byte ptr XMS_Installed,0
- jmp @Outta
- @Inst:
- mov byte ptr XMS_Installed,1
- { Get driver address }
- mov ax,4310h
- int 2fh
- mov word ptr XMS_Driver_Address,bx
- mov word ptr XMS_Driver_Address[2],es
- @Outta:
- pop es
- end;
-
- Function XMSVersion;Assembler;
- asm
- mov ah,0
- call dword ptr XMS_Driver_Address
- { returns in AX version }
- end;
-
- Procedure AllocXMS;Assembler;
- asm
- mov dx,Size
- mov ah,9
- call dword ptr XMS_Driver_Address
- cmp ax,1
- jne @Failure
- push bx
- les bx,dword ptr Handle
- mov word ptr es:[bx],dx
- pop bx
- mov XMS_Error,0
- jmp @Outta
- @Failure:
- mov XMS_Error,bl
- @Outta:
- end;
-
- Procedure QueryXMS;Assembler;
- asm
- mov ah,8
- xor bx,bx
- call dword ptr XMS_Driver_Address
- cmp ax,1
- jne @Failure
- mov word ptr XMS_Total,dx
- mov word ptr XMS_Largest,ax
- mov XMS_Error,0
- jmp @Outta
- @Failure:
- mov XMS_Error,bl
- @Outta:
- end;
-
- Procedure FreeXMS;Assembler;
- asm
- mov ah,10
- mov dx,Handle
- call dword ptr XMS_Driver_Address
- cmp ax,1
- jne @Failure
- mov XMS_Error,0
- jmp @Outta
- @Failure:
- mov XMS_Error,bl
- @Outta:
- end;
-
- Procedure LockXMS;Assembler;
- asm
- mov ah,12
- mov dx,Handle
- call dword ptr XMS_Driver_Address
- cmp ax,1
- jne @Failure
- mov XMS_Error,0
- jmp @Outta
- @Failure:
- mov XMS_Error,bl
- @Outta:
- end;
-
- Procedure UnLockXMS;Assembler;
- asm
- mov ah,13
- mov dx,Handle
- call dword ptr XMS_Driver_Address
- cmp ax,1
- jne @Failure
- mov XMS_Error,0
- jmp @Outta
- @Failure:
- mov XMS_Error,bl
- @Outta:
- end;
-
- Procedure MoveXMS;Assembler;
- asm
- push ds
- mov ah,11
- lds si,EmmStruc
- call dword ptr XMS_Driver_Address
- cmp ax,1
- jne @Failure
- mov XMS_Error,0
- jmp @Outta
- @Failure:
- mov XMS_Error,bl
- @Outta:
- pop ds
- end;
-
- Procedure LocalEnableA20;Assembler;
- asm
- mov ah,5
- call dword ptr XMS_Driver_Address
- cmp ax,1
- jne @Failure
- mov XMS_Error,0
- jmp @Outta
- @Failure:
- mov XMS_Error,bl
- @Outta:
- end;
-
- Procedure LocalDisableA20;Assembler;
- asm
- mov ah,6
- call dword ptr XMS_Driver_Address
- cmp ax,1
- jne @Failure
- mov XMS_Error,0
- jmp @Outta
- @Failure:
- mov XMS_Error,bl
- @Outta:
- end;
-
- Procedure CopyToXMS;
- Var P:Pointer;
- begin
- P:=@Source;
- XMS_Move.Count:=Count;
- XMS_Move.SourceHandle:=0;
- Move(p,XMS_Move.OffsetIntoSource,4);
- XMS_Move.DestHandle:=Handle;
- XMS_Move.OffsetIntoDest:=Offs;
- MoveXMS(XMS_Move);
- end;
-
- Procedure CopyFromXMS;
- Var P:Pointer;
- begin
- P:=@Dest;
- XMS_Move.Count:=Count;
- XMS_Move.SourceHandle:=Handle;
- XMS_Move.OffsetIntoSource:=Offs;
- XMS_Move.DestHandle:=0;
- Move(p,XMS_Move.OffsetIntoDest,4);
- MoveXMS(XMS_Move);
- end;
-
- Procedure CopyXMStoXMS;
- begin
- XMS_Move.Count:=Count;
- XMS_Move.SourceHandle:=SHandle;
- XMS_Move.OffsetIntoSource:=SOffs;
- XMS_Move.DestHandle:=DHandle;
- XMS_Move.OffsetIntoDest:=DOffs;
- MoveXMS(XMS_Move);
- end;
-
- Function CountXMS : Word;
- var k,hand:word;
- begin
- k:=1; XMS_Error:=0;
- AllocXMS(hand,k);
- while XMS_Error=0 do begin
- FreeXMS(hand);
- inc(k);
- AllocXMS(hand,k);
- end;
- dec(k);
- CountXMS:=k;
- end;
-
- begin
- XMS_Driver_Address:=Nil;
- XMS_Installed:=False;
- CheckXMSInstall;
- end.